package com.pt.pok.protobuf;

import com.pt.pok.ProtocolMarshaller;
import com.pt.pok.generated.Commands;
import com.pt.pok.model.LoginRequest;
import com.pt.pok.model.PokerCommand;

/**
 * @author Roman.Ivanov@playtech.com, Andrey.Panfilov@playtech.com
 * @date 1/23/12 TODO: comment please
 */
class LoginCommandMarshaller
    implements ProtocolMarshaller<byte[]> {

    public byte[] convertToProtocolCommand(PokerCommand command) {
        LoginRequest loginRequest = (LoginRequest) command;
        Commands.LoginRequest login = buildLogin(loginRequest.getUsername(), loginRequest.getPassword());
        return login.toByteArray();
    }

    private Commands.LoginRequest buildLogin(String username, String password) {
        return Commands.LoginRequest.newBuilder().setUsername(username).setPassword(password).build();
    }
}
